package com.learner.blog.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.learner.blog.service.MainBlogService;
import com.learner.common.page.PageHelp;
import com.learner.pojo.blog.Blog;
import com.learner.pojo.blog.BlogType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author ice2020x
 * @Date: 2023/2/24
 * @Description: 博客
 **/
@RestController
@RequestMapping("/api/blog/content")
public class MainBlogController {

    @Autowired
    private MainBlogService mainBlogService;


    /**
     * 查询博客列表
     *
     * @param pageHelp 分页参数
     * @return 结果
     */
    @PostMapping("/queryAll")
    public IPage<Blog> queryPageBlog(@RequestBody PageHelp pageHelp) {
        return mainBlogService.getPageBlog(pageHelp);
    }


    /**
     * 根据id获取博客信息
     *
     * @param id id
     * @return 结果
     */
    @GetMapping("/queryById/{id}")
    public Blog queryBlogById(@PathVariable("id") String id) {
        return mainBlogService.getOneBlog(id);
    }


    /**
     * 添加博客
     *
     * @param blog 博客信息
     * @return 结果
     */
    @PostMapping("add")
    public Blog insertBlog(@RequestBody Blog blog) {
        return mainBlogService.addBlog(blog);
    }


    /**
     * 根据id删除博客信息
     *
     * @param id 博客id
     */
    @DeleteMapping("/delete/{id}")
    public void deleteById(@PathVariable("id") String id) {
        mainBlogService.deleteBlogById(id);
    }


    /**
     * 获取博客分类列表
     *
     * @return 结果
     */
    @GetMapping("/cate/list")
    public List<BlogType> findCateList() {
        return mainBlogService.findCateList();
    }

}

